package scct.yzx.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBUtils {
    private static String Driver = "com.mysql.cj.jdbc.Driver";
    private static String URL = "jdbc:mysql://localhost:3306/chatrecord?useUnicode=true&characterEncoding=utf8";
    private static String User = "root";
    private static String Pass = "123456";


    public static Connection getConnection() {
        Connection conn;
        try {
            Class.forName(Driver);
            conn = DriverManager.getConnection(URL, User, Pass);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return conn;
    }


    public static void closeConnection(Connection conn) {
        if (conn != null) {
        try {
            conn.close();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
    }
}
